package com.xzm;

public class InnerclassSingletonTest{
    public static void main(String[]args){
        new Thread(()->{
            InnerclassSingleton instance1 = InnerclassSingleton.getInstance();
            System.out.println(instance1);
        }).start();
        new Thread(()->{
            InnerclassSingleton instance1 = InnerclassSingleton.getInstance();
            System.out.println(instance1);
        }).start();
    }
}

class InnerclassSingleton{
    private static class InnerclassHolder{
        private static InnerclassSingleton instance = new InnerclassSingleton();
    }
    private InnerclassSingleton(){
        //私有构造函数，防止外部进行初始化
    }
    public  static InnerclassSingleton getInstance(){
        return InnerclassHolder.instance;
    }
}
